$(function () {
    //查询所有关注
    //status 1：售卖中,3已过期
    User.attention.find.execution(1);
    var data=User.attention.find.getResult();
    if(data=="执行异常") {

    }else{
        switch (parseInt(data.errorCode)) {
            case 0000:
                $(".fr.right").html('<div class=" xka2">\n' +
                    '\t\t\t\t<a href="two.html"><span class="xka2-0">出售中</span></a>\n' +
                    '\t\t\t\t<a href="two1.html"><span>已过期</span></a>\n' +
                    '\t\t\t</div>');
                //遍历数据添加信息
                /*
                commodityId:1
                commodityName:"《哪吒》 真人巡回演出，带你回忆童年 山西站"
                disPrice:420
                imgURL:null
                placeName:"山西省体育中心体育馆"
                sessionTime:"2019-08-04 A场"
                status:1
                */
                for (var i=0;i<data.data.length;i++){
                    var item=data.data[i];
                    $(".fr.right").append('<div class="clearfix xka2-1">\n' +
                        '\t\t\t\t<div class="fl">\n' +
                        '\t\t\t\t\t<a href="javascript:;" class="fl"><img src="'+item.commodityVo.imgURL+'"></a>\n' +
                        '\t\t\t\t\t<div class="fl xka2-2">\n' +
                        '\t\t\t\t\t\t<a href="javascript:;"><span>'+item.commodityVo.commodityName+'</span></a><br>\n' +
                        '\t\t\t\t\t\t<span>'+item.commodityVo.placeName+'</span><br>\n' +
                        '\t\t\t\t\t\t<span>'+item.commodityVo.sessionTime+'</span>\n' +
                        '\t\t\t\t\t\t<p class="xka2-3">'+(item.commodityVo.status==1?"出售中":item.commodityVo.status==2?"暂停售卖":item.commodityVo.status==3?"已过期":item.commodityVo.status==0?"下架":"未知状态")+'</p>\n' +
                        '\t\t\t\t\t\t<p class="xka2-4">￥'+item.commodityVo.disPrice+'<span>起</span></p>\n' +
                        '\t\t\t\t\t</div>\n' +
                        '\t\t\t\t</div>\n' +
                        '\t\t\t\t<span class="fr removeAttention" _attentionId="'+item.attention.attentionId+'" _commodityId="'+item.commodityVo.commodityId+'">取消关注</span>\n' +
                        '\t\t\t</div>')
                }
                break;
            case 1011:
                break;
            case 0001:
                break;
            case 1012:
                break;
        }
        layer.msg(data.msg);
    }
    $(".fr.right").on("click",".removeAttention",function (e) {
        var attentionId=$(this).attr("_attentionId");
        var commodityId=$(this).attr("_commodityId")
        User.attention.remove.execution(attentionId,commodityId);
        var data=User.attention.remove.getResult();
        if(data=="执行异常") {

        }else{
            switch (parseInt(data.errorCode)) {
                case 0000:
                    $(this).parents(".clearfix.xka2-1").remove();
                    break;
                case 1011:
                    break;
                case 0001:
                    break;
                case 1012:
                    break;
            }
            layer.msg(data.msg);
        }

    });

});